import kMeans
from numpy import *

datMat = mat(kMeans.loadDataSet('testSet.txt'))
print("datMat\n",datMat)
#测试生成2个簇心
twoPoints = kMeans.randCent(datMat,2)
print("kMeans.randCent(datMat,2)\n",twoPoints)
#使用欧式距离计算下距离
kDist = kMeans.distEclud(datMat[0],datMat[1])
print("kMeans.distEclud(datMat[0],datMat[1])\n",kDist)

myCentroids , clustAssing = kMeans.kMeans(datMat,4)
print("myCentroids \n",myCentroids )
#print("myCentroids , clustAssing\n",myCentroids , clustAssing)

########################二分K均值################
datMat3 = mat(kMeans.loadDataSet('testSet2.txt'))
#根据SSE的最小值原理，用二分K均值划分
centList , myNewAssments = kMeans.biKmeans(datMat3,3)
print("cenList\n",centList)

#################应用##############
#根据地图上的点进行聚类
kMeans.clusterClubs(5)
